package com.yxh.www.author.controller;


import com.yxh.www.author.api.AuthorSmUserObjectRelationApi;
import com.yxh.www.author.service.SmUserObjectRelationService;
import com.yxh.www.common.result.Result;
import io.swagger.annotations.Api;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统用户对象关系表 前端控制器
 * </p>
 *
 * @author Yangxiaohui
 * @since 2020-05-09
 */
@Api(tags = "系统用户对象（角色、组织）关系管理")
@RestController
public class SmUserObjectRelationController implements AuthorSmUserObjectRelationApi {
    private final SmUserObjectRelationService smUserObjectRelationService;

    public SmUserObjectRelationController(SmUserObjectRelationService smUserObjectRelationService) {
        this.smUserObjectRelationService = smUserObjectRelationService;
    }

    /**
     * 新增系统用户对象关系
     *
     * @param userId     用户ID    必填
     * @param objectIds  对象ID    必填
     * @param objectType 对象类型（0：角色；1：组织） 默认值0
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> addSmUserObjectRelation(String userId, String[] objectIds, String objectType) {
        return smUserObjectRelationService.addSmUserObjectRelation(userId, objectIds, objectType);
    }

    /**
     * 根据用户对象关系ID删除关系
     *
     * @param ids 关系ID集合
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> removeSmUserObjectRelation(String[] ids) {
        return smUserObjectRelationService.removeSmUserObjectRelation(ids);
    }

    /**
     * 根据用户ID删除 用户对象关系
     *
     * @param userId 用户ID    必填
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> removeSmUserObjectRelationByUserId(String userId) {
        return smUserObjectRelationService.removeSmUserObjectRelationByUserId(userId);
    }

    /**
     * 根据对象ID删除 用户对象关系
     *
     * @param objectId 对象ID  必填
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> removeSmUserObjectRelationByObjectId(String objectId) {
        return smUserObjectRelationService.removeSmUserObjectRelationByObjectId(objectId);
    }

    /**
     * 根据用户ID和 对象ID 解除用户对象关系
     *
     * @param userId   用户ID    必填
     * @param objectId 对象ID    必填
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> removeSmUserObjectRelationByUserIdAndObjectId(String userId, String objectId) {
        return smUserObjectRelationService.removeSmUserObjectRelationByUserIdAndObjectId(userId, objectId);
    }
}
